//
//  YWVideoController.m
//  YWPhotoEditMaster
//
//  Created by jun peng on 2023/9/25.
//

#import "YWVideoController.h"
#import "YWVedioView.h"

@interface YWVideoController ()<YWVedioViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *playbtn;

@property (nonatomic, strong) YWVedioView * vedioView; // 播放器
@end

@implementation YWVideoController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 创建播放器
    YWVedioView *vedioView = [YWVedioView videoView];
    
    self.vedioView = vedioView;
    
    vedioView.delegate = self;
    
    [self.view addSubview:self.vedioView];
    
    [self.view bringSubviewToFront:self.playbtn];
    
    
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    
    self.playbtn.hidden = YES;
    
    [self.vedioView setVedioUrl:self.saveVideoUrl];

    [self.vedioView.player play];
}

//autolayout要获取frame从这里获取
- (void)viewDidLayoutSubviews {
    
    [super viewDidLayoutSubviews];
    
    self.vedioView.frame = self.view.frame;
    
    
}

//离开此页面要停止播放
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
    [self.vedioView pause];
    
}



-(void)vedioView:(YWVedioView *)videoView didTapWithTag:(BOOL)isTag{
    
    if (isTag) {
        [self.vedioView pause];
        self.playbtn.hidden = NO;
    }
    else{
        [self.vedioView continueToPlay];
        self.playbtn.hidden = YES;
        
    }
    
}


@end
